@import com.mgfireworks.mgplatform.mgadmin.product.model.*
@import com.mgfireworks.mgplatform.mgadmin.sys.model.*
@import cn.hn.java.summer.utils.JsonUtils
@extends("/form_template")
@args Boolean isEdit
@args Product product,ProductDetail productDetail,List<Category> categoryList,List<Band> bandList,List<SellLevel> sellLevelList
@{
	if(product==null){
		product=new Product();
	}
	if(productDetail==null){
		productDetail=new ProductDetail();
	}
}
       <div class="x_title row">
			<h2 class="col-xs-2">@if(isEdit){修改}else{添加}产品</h2>
			<div class="col-xs-10">
				<ul id="myTab" class="nav nav-tabs bar_tabs" role="tablist">
					<li role="presentation" class="active">
						<a href="#tab_content1" id="home-tab" role="tab" data-toggle="tab" aria-expanded="true">基本信息</a>
					</li>
					<li role="presentation" class="">
						<a href="#tab_content2" role="tab" id="profile-tab" data-toggle="tab" aria-expanded="false">产品详情</a>
					</li>
					<li role="presentation" class="">
						<a href="#tab_content3" role="tab" id="profile-tab2" data-toggle="tab" aria-expanded="false">其它信息</a>
					</li>
				</ul>
			</div>
       </div>
       <div class="x_content">
       	<div id="myTabContent" class="tab-content">
           <div role="tabpanel" class="tab-pane fade active in" id="tab_content1" aria-labelledby="home-tab">
			   <f_input name="productId" text="产品编号" value="@product.getProductId()" placeholder="自动生成" readonly="readonly"></f_input>
			   <f_input name="productName" text="产品名" value="@product.getProductName()"></f_input>
		       <div class="form-group">
		         <label class="control-label col-md-3 col-sm-3 col-xs-12" for="categoryName">类别
		         </label>
		         <div class="col-md-6 col-sm-6 col-xs-12">
		         	<div id="jsProductCateTree"></div>
		         	<input type="hidden" id="jsCateId" name="cateId" value="@product.getCateId()" required="required"/>
		         </div>
		       </div>

			   <f_select name="bandId" text="品牌">
				   <option value="">请选择品牌</option>
				   @if(bandList){
				   @for(Band b : bandList){
				   <option value="@b.getBandId()">@b.getBandName()</option>
				   }}
			   </f_select>
		       <div class="form-group">
		         <label class="control-label col-md-3 col-sm-3 col-xs-12" for="mainImg">主图片
		         </label>
		         <div class="col-md-6 col-sm-6 col-xs-12">
		         	<img class="product-main-img" src="@url("/)@product.getMainImg()"/>
		         	<div class="x_panel">
	                  <div class="x_title collapse-link">
	                    <button type="button" class="btn btn-primary btn-sm">上传图片</button>
	                    <ul class="nav navbar-right panel_toolbox">
	                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a></li>
	                    </ul>
	                    <div class="clearfix"></div>
	                  </div>
	                  <div class="x_content" style="display: none;">
			         	<input type="text" id="mainImg" name="mainImg" value="@product.getMainImg()" readonly="readonly" class="form-control col-md-7 col-xs-12">
			         	<div class="dropzone dz-clickable dz-started uploader-img"></div>
	                  </div>
	                </div>
		         	
		         </div>
		       </div>
			   <f_select name="sellLevel" text="销售级别">
				   <option value="">请选择销售级别</option>
				   @if(sellLevelList){
				   @for(SellLevel s : sellLevelList){
				   <option value="@s.getLevel()">@s.getLevelName()</option>
				   }}
			   </f_select>
			   <f_radio name="recommend" value="@product.getRecommend()" text="是否推荐" text1="推荐" text2="不推荐"></f_radio>
           </div>
           <div role="tabpanel" class="tab-pane fade" id="tab_content2" aria-labelledby="profile-tab">
           		<div class="form-group">
			        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="description">描述<span class="required">*</span>
			        </label>
			        <div class="col-md-6 col-sm-6 col-xs-12">
			          <textarea type="text" id="description" name="description" placeholder="请输入产品简要描述信息" class="form-control col-md-7 col-xs-12">
			          	@productDetail.getDescription()
			          </textarea>
			        </div>
		  		</div>
           </div>
           <div role="tabpanel" class="tab-pane fade" id="tab_content3" aria-labelledby="profile-tab">
           </div>
         </div>
       </div>
    @section(script){
       <script type="text/javascript">
       $(function(){
       	 var cateList=JSON.parse('@JsonUtils.toJson(categoryList)');
       	 var cateTree=module.category.genCateTree(cateList,"请选择","0",$("#jsCateId").val());
       
       	 $('#jsProductCateTree').treeview({
       	 	levels:10,
       	 	color: "#428bca",
			nodeIcon: "fa fa-leaf",
			showTags: true,
       	 	data:cateTree,
       	 	onNodeSelected:function(event, node){
       	 		$("#jsCateId").val(node.value);
       	 		getNewProductId();
       	 	}
       	 });
       	 $("#jsBandId").change(function(){
       	 	getNewProductId();
       	 });
       
       	 //取新产品编号
       	 function getNewProductId(){
	       	 @if(isEdit){
	       	 return;
	       	 }
       	 	$.get("newpid.json",{
	       	 	cateId:$("#jsCateId").val(),
	       	 	bandId:$("#jsBandId").val()
       	 	},function(r){
       	 		$("#jsProductId").val(r.data);
       	 	});
       	 }
       });
       </script>
    }
       
